<template>
  <div style="width: 99%;  margin: auto;">
    <el-row style="margin-top: 20px;">
      <el-col :span="18"><h3>公益慈善活动支出</h3></el-col>
      <el-col :span="6" style="text-align: right;">
        <el-button style="width: 100px;margin-top: 10px;"  size="default" type="primary"
                   @click="addList()">新增
        </el-button>
      </el-col>
    </el-row>


    <el-form :model="listForm" ref="listFormRef">
    <el-row>
      <el-col :span="24" >
        <el-table :header-cell-style="{background: '#F0F5FA',color: '#333333'}" size="default" :data="listForm" border>
          <el-table-column type="index" label="序号" align="center" width="60" />
          <el-table-column prop="examineYear" label="年度" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].examineYear'" :rules="listRules.examineYear">
              <el-input :disabled="true" type="number"  size="default" v-model="scope.row.examineYear" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="upYearAssets" label="上年末净资产(人民币元)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].upYearAssets'" :rules="listRules.upYearAssets">
              <el-input type="number"  size="default" v-model="scope.row.upYearAssets" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="publicWelfareExpenditure" label="公益慈善事业支出(人民币元)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].publicWelfareExpenditure'" :rules="listRules.publicWelfareExpenditure">
              <el-input type="number"  size="default" v-model="scope.row.publicWelfareExpenditure" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="expenditure" label="当年总支出(人民币元)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].expenditure'" :rules="listRules.expenditure">
              <el-input type="number"  size="default" v-model="scope.row.expenditure" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="manageExpenditure" label="管理费用支出(人民币元)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].manageExpenditure'" :rules="listRules.manageExpenditure">
              <el-input type="number"  size="default" v-model="scope.row.manageExpenditure" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="charitableProportion" label="公益慈善事业支出占上年末净资产的比例(%)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].charitableProportion'" :rules="listRules.charitableProportion">
              <el-input type="number"  size="default" v-model="scope.row.charitableProportion" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column prop="manageProportion" label="管理费支出占当年总支出的比例(%)" align="center">
            <template #default="scope">
              <el-form-item :prop="'[' + scope.$index + '].manageProportion'" :rules="listRules.manageProportion">
              <el-input type="number"  size="default" v-model="scope.row.manageProportion" placeholder="请输入"></el-input>
              </el-form-item>
            </template>
          </el-table-column>
          <el-table-column
            fixed="right"
            label="操作"
            align="center"
            width="80">
            <template #default="scope">
              <el-button type="text"  size="default" @click="handleDelete(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-col>
    </el-row>
    </el-form>
    <el-dialog title="公益慈善活动支出" v-model="addDialog">
      <el-form  size="default" :model="postForm" ref="postForm" label-position="top">
        <el-row :gutter="20">
          <el-col :span="22">
            <el-form-item label="年份" prop="examineYear">
              <el-input v-model="postForm.examineYear" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="上年末净资产(人民币元)" prop="upYearAssets">
              <el-input v-model="postForm.upYearAssets" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="公益慈善事业支出(人民币元)" prop="publicWelfareExpenditure">
              <el-input v-model="postForm.publicWelfareExpenditure" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="当年总支出(人民币元)" prop="expenditure">
              <el-input v-model="postForm.expenditure" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="管理费用支出(人民币元)" prop="manageExpenditure">
              <el-input v-model="postForm.manageExpenditure" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="公益慈善事业支出占上年末净资产的比例(%)" prop="charitableProportion">
              <el-input v-model="postForm.charitableProportion" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="22">
            <el-form-item label="管理费支出占当年总支出的比例(%)" prop="manageProportion">
              <el-input v-model="postForm.manageProportion" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="addDialog = false">取 消</el-button>
        <el-button type="primary" @click="addList()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {getTableInfoByPage, mfSaveExpenditure} from "@/views/yearCheck/ykb/mf/mf";

export default {
  data() {
    return {
      addDialog: false,
      postForm: {
        charitableProportion: '',//公益慈善事业支出占上年末净资产的比例
        creditCode: localStorage.getItem("creditCode"),//统一社会信用代码
        examineYear: localStorage.getItem("examineYear"),
        expenditure: '',//当年总支出
        id: '',//公益慈善活动支出id
        manageExpenditure: '',//管理支出
        manageProportion: '',//管理费支出占当年总支出的比例
        organizationBaseId: '22',//组织id
        publicWelfareExpenditure: '',//公益支出
        upYearAssets: '',//上年末净资产
      },
      listForm: [],
      listRules: {
        charitableProportion: [{ required: true, message: '请完善', trigger: 'blur' }],
        expenditure: [{ required: true, message: '请完善', trigger: 'blur' }],
        manageExpenditure: [{ required: true, message: '请完善', trigger: 'blur' }],
        manageProportion: [{ required: true, message: '请完善', trigger: 'blur' }],
        publicWelfareExpenditure: [{ required: true, message: '请完善', trigger: 'blur' }],
        upYearAssets: [{ required: true, message: '请完善', trigger: 'blur' }]
      }
    }
  },

  created() {

  },
  methods: {
    handleDelete(index) {
      this.listForm.splice(index, 1);
    },
    postInfo(){

      this.$refs.listFormRef.validate(valid=> {
        if (valid) {
          if(this.listForm == null || this.listForm.length == 0){
            return;
          }
          for (let i = 0; i < this.listForm.length; i++) {
            this.listForm[i].creditCode = localStorage.getItem("creditCode");
            this.listForm[i].examineYear = localStorage.getItem("examineYear");
          }
          mfSaveExpenditure(this.listForm).then(response => {
            this.$message({
              message: '保存公益慈善活动支出成功！',
              type: 'success'
            });
            this.getInfo();
          });
        }else{
          this.$message({
            message: '请填写完整！',
            type: 'error'
          });
        }
      });
    },
    addList(){
      // this.addDialog = false;
      this.listForm.push(Object.assign({}, this.postForm))
    },
    getInfo(){
      getTableInfoByPage(22).then(response => {
        this.listForm = JSON.parse(JSON.stringify(response.data).replace(/null/g, '""'));
        if (this.listForm == null  || this.listForm == '') {
          this.listForm = [];
        }
      });
    }
  }
}
</script>
<style scoped lang="scss">
.el-table {
  --el-table-row-hover-bg-color: rgba(39, 137, 238, 0.1);
  --el-table-border-color:#e0e5f0;
}
:deep(.el-card.is-always-shadow) {
  box-shadow: 0 1px 14px 0 rgba(209, 224, 239, 0.6)
}

/* 拉框选中 */
.el-select-dropdown__item {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

/* 鼠标经过下拉框 */
.el-select-dropdown__item:hover {
  height: 24px;
  line-height: 24px;
  font-size: 12px;
}

.el-select-dropdown__item.selected {
  color: #2789EE;
}
.app-container {
  margin-top: 40px;
  margin-left: 15%;
  width: 70%;
}

.div-bg {
  width: 100%;
  background: #F0F0F0;
  height: 10px;
}

.box-card {
  width: 100%;
  margin-top: 20px;
  padding: 20px;
}

.el-col {
  padding-left: 5px;
}

.divider-title {
  font-weight: bold;
  font-size: 18px;
}

.custom-select .el-select-dropdown {
  max-height: 600px; /* 设置为你想要的高度 */
  overflow: auto; /* 添加滚动条 */
}

table {
  border-collapse: collapse; /* 确保表格的边框合并为单一边框 */
  width: 100%; /* 表格宽度 */
}

td {
  border: 1px solid #ababab; /* 设置单线边框 */
  padding: 6px; /* 单元格内边距 */
}
.el-form-item {
  margin-bottom: 0px;
}
</style>
